import React, { Component } from 'react';
import CustomBreadcrumb from '../../components/CustomBreadcrumb';
import EditCompany from './components/EditCompany';
import { hashHistory } from 'react-router';
import { CompanyService } from '../../services'

export default class Company extends Component {
  static displayName = 'Company';

  constructor(props) {
    super(props);
    this.state = {
      value : {
        ...this.props.location.state,
        id : this.props.params.id,
      }
    };
  }

  onSubmit = async(data) =>{
    await CompanyService.update(data)
    hashHistory.push('/company/list')
    return true
  }

  render() {
    const breadcrumb = [
      { text: '公司管理', link: '#/company/list' },
      { text: '修改公司', link: null },
    ];
    return (
      <div className="company-page">
        <CustomBreadcrumb dataSource={breadcrumb} />
        <EditCompany value={this.state.value} onSubmit={this.onSubmit}/>
      </div>
    );
  }
}
